import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		// 更换负责人
		formData:[
			{ label: '负责人',	name: 'newUserUuid', 	type: 'select', full:true,  loading:true,  required:true },
		]
	}
	
	model = {}
	
	open = ({ id, leader_id }) => {
		this.modal.open({ formRef:this.formRef })
		this.submit = { id, userUuid:leader_id }
		
		this.getModalSelect()
	}

	// 获取下拉数据
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, [ 'newUserUuid' ], ()=>{
			$cache.then( async f => {
				// 真实姓名
				$fn.setRow(formData, 'newUserUuid', await f.getCache({ api:'salesman' } ) )
				
				this.formRef.setValue({ newUserUuid: this.submit.userUuid })
				//
				this.setState({ formData })
			})
		})
		
		if($fn.hasArray(formData[0].data)){
			this.formRef.setValue({ newUserUuid: this.submit.userUuid })
		}
	}
	
	render(){
		return FormModal.call(this,{ title:'更换负责人', width:'40%', minWidth:600, api: 'bs-area/changeRegionalSuper', onOk: ()=>{this.props.onRefresh()}})
	}
}

export default Index